let mysql = require('mysql')
let config = require('../config')

let pool = mysql.createPool(config.database)
let query = (sql, params) => {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, conn) => {
            if (err) {
                reject(err)
            }else {
                conn.query(sql,params, (err, result) => {
                    conn.release()
                    if(err) {
                        reject(err)
                    }else {
                        resolve(result)
                    }
                })
            }
        })
    })
}
module.exports = query